import {BASE_URL} from '@/config';

export const http = (url,method,data,showToast = true) => {
	return new Promise((resolve, reject) => {
		const header = {
			'Content-Type': 'application/json'
		}
		uni.request({
			url: BASE_URL + url,
			method,
			data: data || {},
			header,
			success(res) {
				if(res.data.code === 200) {
					resolve(res.data)
				} else {
					if(showToast) {
						uni.$u.toast(res.data.msg)
					}
					reject(res.data)
				}
			},
			fail(err) {
				if(showToast) {
					uni.$u.toast(err.msg)
				}
				reject(err)
			}
		})
	})
}